//package me.ezjs.base.manager.impl;
//
//import me.ezjs.base.manager.BusinessLogManager;
//import me.ezjs.base.mapper.BusinessLogMapper;
//import me.ezjs.base.model.BusinessLog;
//import me.ezjs.base.model.LogType;
//import me.ezjs.core.manager.impl.GenericManagerImpl;
//import me.ezjs.core.model.FlipFilter;
//import me.ezjs.core.model.Operate;
////import me.ezjs.utils.shortmsg.ShortMsgUtil;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//@Service
//public class BusinessLogManagerImpl extends GenericManagerImpl<BusinessLog, Integer> implements BusinessLogManager {
//
//    @Autowired
//    public BusinessLogManagerImpl(BusinessLogMapper mapper) {
//        super(mapper, BusinessLog.class);
//    }
//
//    public void sendVerificationCode(String tel, String code, ShortMsgUtil.Template template) {
//        //查看上次发送时间
//        FlipFilter filter = new FlipFilter(BusinessLog.class);
//        filter.addSearch(tel, Operate.EQUAL, "logKey");
//        filter.addSearch("200", Operate.EQUAL, "logRes");
//        filter.addSort("createTime", true);
//        BusinessLog lastBlog = mapper.getFirstByFilter(filter);
//        if (lastBlog != null) {
//            //一分钟内刚发过短信,不再发送了.
//            if (System.currentTimeMillis() < lastBlog.getCreateTime().getTime() + 1 * 60 * 1000) {
//                return;
//            }
//        }
//
//
//        BusinessLog blog = new BusinessLog();
//        blog.setLogType(LogType.verification_code.getIndex());
//        blog.setLogKey(tel);
//        blog.setLogValue(code);
//        mapper.create(blog);
//
//        try {
//            int b;
//            if (template != null) {
//                b = ShortMsgUtil.sendTemCode(template, tel, code);
//            } else {
//                b = ShortMsgUtil.sendTemCode(ShortMsgUtil.Template.verification_code, tel, code);
//            }
//            blog.setLogRes(b + "");
//            mapper.update(blog);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//    public boolean validateVerificationCode(String tel, String codeFromUser) {
//        //获取指定手机号最新一次的验证码.
//        FlipFilter filter = new FlipFilter(BusinessLog.class);
//        filter.addSearch(tel, Operate.EQUAL, "logKey");
//        filter.addSearch("200", Operate.EQUAL, "logRes");
//        filter.addSort("createTime", true);
//        BusinessLog blog = mapper.getFirstByFilter(filter);
//        if (blog == null) {
//            return false;
//        }
//        if (System.currentTimeMillis() > blog.getCreateTime().getTime() + 6 * 60 * 1000) {
//            return false;
//        }
//        if (blog.getLogValue() != null && blog.getLogValue().equals(codeFromUser)) {
//            return true;
//        }
//        return false;
//    }
//}